package com.company.app.entities;

import java.io.Serializable;
import java.util.Date;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.google.code.ssm.api.CacheKeyMethod;

/**
 * The Class User.
 * 
 * @author parojas
 * @date 27/03/2013
 */
@XmlType(name="Product" , namespace = "http://entities.app.company.com", propOrder = { "id", "name", "price", "code", "description",
		"priceOffer", "percSale", "quantity", "dateCreated", "dateSaleFrom",
		"dateSaleUntil" , "productType" })
@XmlRootElement(name = "Product")
public class Product implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 952659432193852575L;

	/** The id. */
	private Long id;

	/** The name. */
	private String name;

	/** The code. */
	private String code;

	/** The price. */
	private Double price;

	/** The description. */
	private String description;

	/** The price offer. */
	private Double priceOffer;

	/** The perf sale. */
	private Double percSale;

	/** The quantity. */
	private Integer quantity;

	/** The date created. */
	private Date dateCreated;

	/** The date sale from. */
	private Date dateSaleFrom;

	/** The date sale until. */
	private Date dateSaleUntil;

	private ProductType productType;

	/**
	 * Gets the id.
	 * 
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Sets the id.
	 * 
	 * @param id
	 *            the new id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	@XmlElement(name = "name", required = true)
	public String getName() {
		return name;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the code.
	 * 
	 * @return the code
	 */
	@XmlElement(name = "code", required = true)
	public String getCode() {
		return code;
	}

	/**
	 * Sets the code.
	 * 
	 * @param code
	 *            the new code
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * Gets the price.
	 *
	 * @return the price
	 */
	public Double getPrice() {
		return price;
	}

	/**
	 * Sets the price.
	 *
	 * @param price the new price
	 */
	public void setPrice(Double price) {
		this.price = price;
	}

	/**
	 * Gets the price offer.
	 *
	 * @return the price offer
	 */
	public Double getPriceOffer() {
		return priceOffer;
	}

	/**
	 * Sets the price offer.
	 *
	 * @param priceOffer the new price offer
	 */
	public void setPriceOffer(Double priceOffer) {
		this.priceOffer = priceOffer;
	}

	/**
	 * Gets the quantity.
	 * 
	 * @return the quantity
	 */
	@XmlElement(name = "quantity", required = true)
	public Integer getQuantity() {
		return quantity;
	}

	/**
	 * Sets the quantity.
	 * 
	 * @param quantity
	 *            the new quantity
	 */
	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	/**
	 * Gets the date created.
	 * 
	 * @return the date created
	 */
	@XmlElement(name = "dateCreated", required = false)
	public Date getDateCreated() {
		return dateCreated;
	}

	/**
	 * Sets the date created.
	 * 
	 * @param dateCreated
	 *            the new date created
	 */
	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	/**
	 * Gets the date sale from.
	 * 
	 * @return the date sale from
	 */
	@XmlElement(name = "dateSaleFrom", required = false)
	public Date getDateSaleFrom() {
		return dateSaleFrom;
	}

	/**
	 * Sets the date sale from.
	 * 
	 * @param dateSaleFrom
	 *            the new date sale from
	 */
	public void setDateSaleFrom(Date dateSaleFrom) {
		this.dateSaleFrom = dateSaleFrom;
	}

	/**
	 * Gets the date sale until.
	 * 
	 * @return the date sale until
	 */
	@XmlElement(name = "dateSaleUntil", required = false)
	public Date getDateSaleUntil() {
		return dateSaleUntil;
	}

	/**
	 * Sets the date sale until.
	 * 
	 * @param dateSaleUntil
	 *            the new date sale until
	 */
	public void setDateSaleUntil(Date dateSaleUntil) {
		this.dateSaleUntil = dateSaleUntil;
	}

	/**
	 * Gets the description.
	 * 
	 * @return the description
	 */
	@XmlElement(name = "description", required = false)
	public String getDescription() {
		return description;
	}

	/**
	 * Sets the description.
	 * 
	 * @param description
	 *            the new description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the perc sale.
	 * 
	 * @return the perc sale
	 */
	@XmlElement(name = "percSale", required = false)
	public Double getPercSale() {
		return percSale;
	}

	/**
	 * Sets the perc sale.
	 * 
	 * @param percSale
	 *            the new perc sale
	 */
	public void setPercSale(Double percSale) {
		this.percSale = percSale;
	}

	/**
	 * Gets the product type.
	 * 
	 * @return the product type
	 */
	@XmlElement(name = "productType", required = true)
	public ProductType getProductType() {
		return productType;
	}

	/**
	 * Sets the product type.
	 * 
	 * @param productType
	 *            the new product type
	 */
	public void setProductType(ProductType productType) {
		this.productType = productType;
	}
	
	/* (non-Javadoc)
	 *	Also used to generate MEMCACHED key 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Product{id=" + this.getId() + ",name=" + this.getName()
				+ ",price=" + this.getPrice() + ",code="
				+ this.getCode() + "description,=" + this.getDescription() + ",priceOffer=" + this.getPriceOffer() + ",percSale="+ this.getPercSale() + ",quantity=" + this.getQuantity() + ",dateCreated=" + this.getDateCreated() + ",dateSaleFrom=" + 
				this.getDateSaleFrom() + ",dateSaleUntil=" + this.getDateSaleUntil() + ",productType=" + this.getProductType().toString()+ "}";
		
	}

	/**
	 * Gets the cache id.
	 * 
	 * @return the cache id
	 */
	@CacheKeyMethod
	public String getIdForCache() {
		return this.getId() != null ? this.getId().toString() : "NULL";
	}

}
